package com.trt.beibei.api.v1;

import com.trt.beibei.core.interceptors.ScopeLevel;
import com.trt.beibei.exception.http.NotFoundException;
import com.trt.beibei.model.Banner;
import com.trt.beibei.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author tanrentao
 * @date 2021年08月07日 13:41
 * @desc 轮播图控制器
 */
@Validated
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    // 127.0.0.1:8081/v1/banner/name/b-1
    @GetMapping("/name/{name}")
    @ScopeLevel // 测试
    public Banner getByName(@PathVariable @NotBlank String name) {
        Banner banner = bannerService.getByName(name);
        if (banner == null) {
            throw new NotFoundException(30005);
        }
        return banner;
    }

}
